package cn.yourkingda.service.impl;

import java.util.List;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.service.NameEntityService;

import cn.yourkingda.pojo.Food;
import cn.yourkingda.pojo.Saleorderitem;
import cn.yourkingda.service.SaleorderitemService;
import cn.yourkingda.util.MyJson;

public class SaleorderitemServiceImpl extends NameEntityService<Saleorderitem> implements SaleorderitemService{
	
	/**
	 * 更新
	 */
	public MyJson updateSaleorderitem(int order_id,List<Food> list) {
		// TODO Auto-generated method stub
		Dao dao = this.dao();
		for(int i=0;i<list.size();i++){
			Food food = list.get(i);
			Saleorderitem soi = new Saleorderitem();
			soi.setFoodid(food.getId());
			soi.setPrice(food.getPrice());
			soi.setQuantity(food.getNum());
			soi.setSaleorderid(order_id);
			dao.insert(soi);
		}
		MyJson myJson = new MyJson();
		myJson.setStatus(1);
		myJson.setMsg("ok");
		return myJson;
		
	}

	
	public void delSaleorderitem(int id) {
		// TODO Auto-generated method stub
		this.dao().delete(Saleorderitem.class,id);
	}

	
	public Saleorderitem getSaleorderitem(Saleorderitem food) {
		// TODO Auto-generated method stub
		
		return this.dao().fetch(Saleorderitem.class,food.getId());
	}

	/**
	 * 展现数据
	 */
	public List listSaleorderitem() {
		// TODO Auto-generated method stub
		List<Saleorderitem> saleorderitemList = this.dao().query(Saleorderitem.class,Cnd.where("id",">",0).desc("id"));
		return saleorderitemList;
	}

}
